/**
 * 
 */
package com.maohi.software.tupuna.home.bundle.ui;

import java.awt.Dimension;
import java.util.List;

import javax.swing.JButton;

import org.jdesktop.swingx.JXTaskPane;
import org.jdesktop.swingx.JXTaskPaneContainer;

import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.maohi.software.tupuna.interfaces.TupunaController;
import com.maohi.software.tupuna.jaxb2.Menu;

/**
 * @author heifara
 * 
 */
public class BundleMenuUI extends JXTaskPaneContainer {

	private static final long serialVersionUID = 1L;
	private static final Dimension DIMENSION = new Dimension(150, 300);
	private TupunaController controller;
	private String bundleId;

	@Inject
	public BundleMenuUI(TupunaController aController, @Named("bundle") String aBundleId) {
		this.controller = aController;
		this.bundleId = aBundleId;
	}

	@Inject
	protected void initUI() {
		this.setSize(DIMENSION);
		this.setPreferredSize(DIMENSION);
		this.setMinimumSize(DIMENSION);

		List<Menu> iMenus = controller.getModel().getBundleMenusFor(this.bundleId);
		for (Menu iMenu : iMenus) {
			this.createMenu(iMenu);
		}
	}

	private void createMenu(Menu aMenu) {
		JXTaskPane iTaskPane = new JXTaskPane();
		iTaskPane.setTitle(aMenu.getTitle());
		this.add(iTaskPane);

		for (Menu iMenuItem : aMenu.getMenuItem()) {
			iTaskPane.add(new JButton(iMenuItem.getTitle()));
		}
	}

}
